﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace Axe
{
    public static partial class Utility
    {
        private static ImageCodecInfo[] Codecs = null;
        
        #region public static string GetImageMimeType(Image img)
        public static string GetImageMimeType(Image img)
        {
            if (Codecs == null)
                Codecs = ImageCodecInfo.GetImageEncoders();
            int len = Codecs.Length;
            for (int j = 0; j < len; j++)
            {
                if (Codecs[j].FormatID == img.RawFormat.Guid)
                {
                    return Codecs[j].MimeType;
                }
            }

            return null;
        }
        #endregion

        public static RectangleF GetCircleRectangle(float x, float y, float rad)
        {
            float halfRad = rad/2;
            return new RectangleF(x - halfRad, y - halfRad, rad, rad);
        }

        public static RectangleF GetCircleRectangle(double x, double y, double rad)
        {
            double halfRad = rad / 2;
            return new RectangleF((float)(x - halfRad), (float)(y - halfRad), (float)rad, (float)rad);
        }

        public static RectangleF GetEllipseRectangle(double centerX, double centerY, double width, double height)
        {
            double halfW = width / 2;
            double halfH = height / 2;

            return new System.Drawing.RectangleF(
                (float)(centerX - halfW),
                (float)(centerY - halfH),
                (float)width, 
                (float)height);
        }
    }
}
